#include <iostream>
#include <fstream>
#include <bitset>
#include <climits>
#include <memory>

int main() {
    std::ifstream input("./input.bin", std::ios::binary);
    if (!input.is_open()) {
        std::cerr << "错误: 无法打开输入文件 'input.bin'" << std::endl;
        return 1;
    }
    
    std::ofstream output("./output.bin", std::ios::binary);
    if (!output.is_open()) {
        std::cerr << "错误: 无法创建输出文件 'output.bin'" << std::endl;
        return 1;
    }

    auto bitmap = std::make_unique<std::bitset<1ull << 32>>();      // 空间太大了，栈溢出
    
    // 读取并去重
    int number;
    while (input.read(reinterpret_cast<char*>(&number), sizeof(number))) {
        // 将int映射到位图索引
        unsigned int index = static_cast<unsigned int>(number) + (1u << 31);    // INT_MAX + 1
        if (!bitmap->test(index)) {
            bitmap->set(index);
        }
    }
    
    // 从大到小输出
    for (int i = INT_MAX; i >= INT_MIN; --i) {
        unsigned int index = static_cast<unsigned int>(i) + (1u << 31);
        if (bitmap->test(index)) {
            output.write(reinterpret_cast<const char*>(&i), sizeof(i));
        }
    }

    input.close();
    output.close();
    
    return 0;
}